
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 10/09/2012 18:32:46
-- Generated from EDMX file: C:\Users\Bruno\Faculdade\UNIRIO\DSW - Desenvolvimento de Servidor Web\Trabalho\bsi20121-dsw-dnanalysis\DNA_Analysis\DNA_Analysis\Models\DNA_Analysis_Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [DNAAnalysis];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_DiseaseResearchDiseaseProbability]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ResearchDiseaseProbability] DROP CONSTRAINT [FK_DiseaseResearchDiseaseProbability];
GO
IF OBJECT_ID(N'[dbo].[FK_UserPerfil]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[User] DROP CONSTRAINT [FK_UserPerfil];
GO
IF OBJECT_ID(N'[dbo].[FK_ResearchResearchDiseaseProbability]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ResearchDiseaseProbability] DROP CONSTRAINT [FK_ResearchResearchDiseaseProbability];
GO
IF OBJECT_ID(N'[dbo].[FK_UserResearch]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Research] DROP CONSTRAINT [FK_UserResearch];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Disease]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Disease];
GO
IF OBJECT_ID(N'[dbo].[DNA]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DNA];
GO
IF OBJECT_ID(N'[dbo].[Perfil]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Perfil];
GO
IF OBJECT_ID(N'[dbo].[Research]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Research];
GO
IF OBJECT_ID(N'[dbo].[ResearchDiseaseProbability]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ResearchDiseaseProbability];
GO
IF OBJECT_ID(N'[dbo].[User]', 'U') IS NOT NULL
    DROP TABLE [dbo].[User];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Disease'
CREATE TABLE [dbo].[Disease] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'DNA'
CREATE TABLE [dbo].[DNA] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [CompleteDNASequence] nvarchar(max)  NOT NULL,
    [User_Id] int  NOT NULL
);
GO

-- Creating table 'Perfil'
CREATE TABLE [dbo].[Perfil] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Level] int  NOT NULL
);
GO

-- Creating table 'Research'
CREATE TABLE [dbo].[Research] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [DNAPartialPattern] nvarchar(max)  NOT NULL,
    [User_Id] int  NOT NULL
);
GO

-- Creating table 'ResearchDiseaseProbability'
CREATE TABLE [dbo].[ResearchDiseaseProbability] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Probability] float  NOT NULL,
    [Research_Id] int  NOT NULL,
    [Disease_Id] int  NOT NULL
);
GO

-- Creating table 'User'
CREATE TABLE [dbo].[User] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Lastname] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [Perfil_Id] int  NOT NULL,
    [DNA_Id] int  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Disease'
ALTER TABLE [dbo].[Disease]
ADD CONSTRAINT [PK_Disease]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'DNA'
ALTER TABLE [dbo].[DNA]
ADD CONSTRAINT [PK_DNA]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Perfil'
ALTER TABLE [dbo].[Perfil]
ADD CONSTRAINT [PK_Perfil]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Research'
ALTER TABLE [dbo].[Research]
ADD CONSTRAINT [PK_Research]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ResearchDiseaseProbability'
ALTER TABLE [dbo].[ResearchDiseaseProbability]
ADD CONSTRAINT [PK_ResearchDiseaseProbability]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'User'
ALTER TABLE [dbo].[User]
ADD CONSTRAINT [PK_User]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Disease_Id] in table 'ResearchDiseaseProbability'
ALTER TABLE [dbo].[ResearchDiseaseProbability]
ADD CONSTRAINT [FK_DiseaseResearchDiseaseProbability]
    FOREIGN KEY ([Disease_Id])
    REFERENCES [dbo].[Disease]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DiseaseResearchDiseaseProbability'
CREATE INDEX [IX_FK_DiseaseResearchDiseaseProbability]
ON [dbo].[ResearchDiseaseProbability]
    ([Disease_Id]);
GO

-- Creating foreign key on [Perfil_Id] in table 'User'
ALTER TABLE [dbo].[User]
ADD CONSTRAINT [FK_UserPerfil]
    FOREIGN KEY ([Perfil_Id])
    REFERENCES [dbo].[Perfil]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserPerfil'
CREATE INDEX [IX_FK_UserPerfil]
ON [dbo].[User]
    ([Perfil_Id]);
GO

-- Creating foreign key on [Research_Id] in table 'ResearchDiseaseProbability'
ALTER TABLE [dbo].[ResearchDiseaseProbability]
ADD CONSTRAINT [FK_ResearchResearchDiseaseProbability]
    FOREIGN KEY ([Research_Id])
    REFERENCES [dbo].[Research]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ResearchResearchDiseaseProbability'
CREATE INDEX [IX_FK_ResearchResearchDiseaseProbability]
ON [dbo].[ResearchDiseaseProbability]
    ([Research_Id]);
GO

-- Creating foreign key on [User_Id] in table 'Research'
ALTER TABLE [dbo].[Research]
ADD CONSTRAINT [FK_UserResearch]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[User]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserResearch'
CREATE INDEX [IX_FK_UserResearch]
ON [dbo].[Research]
    ([User_Id]);
GO

-- Creating foreign key on [User_Id] in table 'DNA'
ALTER TABLE [dbo].[DNA]
ADD CONSTRAINT [FK_DNAUser]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[User]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DNAUser'
CREATE INDEX [IX_FK_DNAUser]
ON [dbo].[DNA]
    ([User_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------